package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.Quotation;
import com.ruoyi.logistic.domain.vo.QuotationVo;
import com.ruoyi.logistic.mapper.QuotationMapper;
import com.ruoyi.logistic.service.IQuotationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuotationServiceImpl implements IQuotationService {
    @Autowired
    private QuotationMapper quotationMapper;
    @Override
    public List<Quotation> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return quotationMapper.selectAll();
    }

    @Override
    public Boolean insert(Quotation quotation) {
        quotation.setCreateBy(SecurityUtils.getUserId());
        if (quotation.getQuotationNumber() == null){
            quotation.setQuotationNumber(1);
        }else {
            quotation.setQuotationNumber(quotation.getQuotationNumber() + 1);
        }
        return quotationMapper.insert(quotation);
    }

    @Override
    public Boolean update(Quotation quotation) {
        return quotationMapper.update(quotation);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return quotationMapper.deleteById(id);
    }

    @Override
    public Quotation findById(Integer id) {
        return quotationMapper.findById(id);
    }

    @Override
    public List<Quotation> search(QuotationVo quotationVo) {
        PageHelper.startPage(quotationVo.getPageDate());
        return quotationMapper.search(quotationVo);
    }
}
